package com.fenda.servlet;

import com.fenda.Dao.UserDao;
import com.fenda.Util.mybatisUtil;
import com.fenda.pojo.Student;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/delete")
public class DeleteServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        SqlSession sqlSession = mybatisUtil.getSqlSession();
        UserDao mapper = sqlSession.getMapper(UserDao.class);
        int id = Integer.parseInt(req.getParameter("id")) ;
        System.out.println(id);
        int i = mapper.SelectId(id);
        System.out.println(i);
        if(i!=0){
            int delect = mapper.delect(i);
            resp.sendRedirect("index.jsp");
            sqlSession.commit();
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
}
